package service;

import java.util.ArrayList;
import java.util.List;

import beans.CartaBean;
import beans.ComandaBean;
import beans.ItemCartaBean;
import entities.CartaEntity;
import entities.ComandaEntity;
import entities.ItemCartaEntity;

public class CartaSrv {
	
	private static CartaSrv instancia = null;
	
	public static CartaSrv getInstancia() {
		if( instancia == null) {
			instancia = new CartaSrv();
		}
		return instancia;
	}

	public CartaEntity bean2Entity(CartaBean carta) {
		CartaEntity cartaEntity = new CartaEntity();
		cartaEntity.setId(carta.getId());
		List<ItemCartaEntity> itemsCartaEntity = new ArrayList<ItemCartaEntity>();
		for (ItemCartaBean itemCartaBean: carta.getItems()) {
			ItemCartaEntity itemCartaEntity = ItemCartaSrv.getInstancia().bean2Entity(itemCartaBean);
			itemsCartaEntity.add(itemCartaEntity);
		}
		cartaEntity.setItemCartas(itemsCartaEntity);
		return cartaEntity;
	}

	/**
	 * 
	 * @param carta
	 * @return
	 */
	public CartaBean entity2Bean(CartaEntity carta) {
		CartaBean cartaBean = new CartaBean();
		cartaBean.setId(carta.getId());
		List<ItemCartaBean> itemsCartaBean= new ArrayList<ItemCartaBean>();
		for (ItemCartaEntity itemCartaEntity: carta.getItemCartas()) {
			ItemCartaBean itemCartaBean = ItemCartaSrv.getInstancia().entity2Bean(itemCartaEntity);
			itemsCartaBean.add(itemCartaBean);
		}
		cartaBean.setItems(itemsCartaBean);
		return cartaBean;
	}
}
